package com.jrh.web.ajax.pub;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.jrh.biz.user.like.UserLikeWriteService;
import com.jrh.domain.like.DoLikeResult;
import com.jrh.web.member.tools.UserAuthUtil;

/**
 * 喜欢
 * 
 * @author jasen.hsu.cn@gmail.com 2012-8-6 下午8:39:21
 */
@Controller
@RequestMapping("/like_ajax")
public class UserLikeAjax {

    @Autowired
    private UserLikeWriteService userLikeWriteService;

    /**
     * 喜欢(URL方式)
     * 
     * @param refType
     * @param refId
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/{refType}/{refId}")
    public ModelAndView doLike(@PathVariable("refType") int refType, @PathVariable("refId") Long refId,
                               HttpServletRequest request, HttpServletResponse response) {
        Long userId = UserAuthUtil.getUserId(request, response);
        ModelAndView result = new ModelAndView();
        DoLikeResult doLikeResult = userLikeWriteService.like(refType, userId, refId);
        result.addObject("_data_", doLikeResult);
        return result;
    }

    /**
     * 喜欢(参数方式)
     * 
     * @param refType
     * @param refId
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/do_like")
    public ModelAndView doUserLike(int refType, Long refId, HttpServletRequest request, HttpServletResponse response) {
        Long userId = UserAuthUtil.getUserId(request, response);
        ModelAndView result = new ModelAndView();
        DoLikeResult doLikeResult = userLikeWriteService.like(refType, userId, refId);
        result.addObject("_data_", doLikeResult);
        return result;
    }

}
